#!/usr/bin/python3

from tkinter import *

class Application(Frame):#继承Frame类
    """Build the basic window frame template"""

    def __init__(self, master):#构造函数的定义
        super(Application, self).__init__(master)#父类构造函数参数的传递
        self.grid()#打开网格定位控件
        self.create_widgets()#自定义函数

    def create_widgets(self):
        self.label1 = Label(self, text="Welcome to my window!")#一个Label方法的使用
        self.label1.grid(row=0, column = 0, sticky=W)#使用grid实现label的定位和对齐方式
        self.button1 = Button(self, text='Click me!', command=self.display)
        #按钮控件的触发事件函数display.
        self.button1.grid(row=1, column=0, sticky=W)#按钮控件的定位和左对齐

    def display(self):
        """Event handler for the button"""
        print('The button in the window was clicked!')
        #该函数实现点击按钮，实现在交互shell打印一句话.


root = Tk()#对象实例化
root.title('Test Application window with label')#窗口的标题
root.geometry('300x100')#窗口的大小
app = Application(root)#将窗口放入框架
app.mainloop()#对整个框架进行事件驱动监听
